package com.bjfu.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjfu.common_utils.R;
import com.bjfu.eduservice.entity.EduCourse;
import com.bjfu.eduservice.entity.EduTeacher;
import com.bjfu.eduservice.service.EduCourseService;
import com.bjfu.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
//@CrossOrigin
@Api("教师前台展示")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    // 1. 分页查询讲师方法
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(
            @PathVariable long page,
            @PathVariable long limit
    ){
        Page<EduTeacher> pageTeacher = new Page<EduTeacher>(page,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);
        // 前台我们自己写分页所以分页结果需要全部返回

        return R.ok().data(map);
    }


    //2 讲师详情的功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        EduTeacher teacher = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }


}
